<?php
require_once './Class/AbstractGet.php';
require_once 'Lib/PHPExcel.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GetGPW
 *
 * @author mateusz.ledzewicz
 */

/*
 *              'dateFrom' => '2014-12-10',
                'dateTo' => '2014-12-26',
                'instrumentType' => '10',
                'isin' => 'PLNFI0600010'
 */






class GetGPW extends AbstractGet {
    private $gpw = ConfigPath::gpwHref;
    
     
    private static $pathXLS         = 'temp/temp.xls';
    private static $pathCSV         = 'temp/temp.csv';
    
    public function getArray() {
       return array_reverse($this->dataArray);
    }
    
    protected function init($dateFrom, $dateTo, $instrumentType, $isin) {
        $postdata = http_build_query(
            array(
                'dateFrom' => $dateFrom,
                'dateTo' => $dateTo,
                'instrumentType' => $instrumentType,
                'isin' => $isin
            )
        );

        $optsGpw = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => 'Content-type: application/x-www-form-urlencoded',
                'content' => $postdata
            )
        );
        
        $contextGpw  = stream_context_create($optsGpw);
        $this->data = file_get_contents($this->gpw, false, $contextGpw); 
        file_put_contents(self::$pathXLS, $this->data);
        
        $reader = PHPExcel_IOFactory::createReader('Excel5');
        $reader->setReadDataOnly(true); 
        $excel = $reader->load(self::$pathXLS);
       
        $writer = PHPExcel_IOFactory::createWriter($excel, 'CSV');
        $writer->save(self::$pathCSV);
        $this->data = file_get_contents(self::$pathCSV);
        
        unlink(self::$pathCSV);
        unlink(self::$pathXLS);
        
    }
    
  

    protected function createMapper() {
        
         self::$mapper = array
        (
            'date'                      => 1,
            'openPrice'                 => 5,
            'highPrice'                 => 6,
            'lowPrice'                  => 7,
            'closePrice'                => 8,
            'change'                    => 9,
            'volume'                    => 10, 
            'transactionNumber'         => 11,
            'value'                     => 12   
        );
    }
    
   
    

    
}

?>
